import { BasicColumn } from "/@/components/Table"
import { FormSchema } from "/@/components/Table"
import { getAllRolesList, getAllTenantList } from "./user.api"
import { rules } from "/@/utils/helper/validator"
import { render } from "/@/utils/common/renderUtils"
import { DescItem } from "/@/components/Description/index"
import { UploadBizType } from "/@/enums/uploadEnum"

export const columns: BasicColumn[] = [
  {
    title: "头像",
    dataIndex: "avatar",
    width: 80,
    customRender: (record : any) => {
      return render.renderAvatar(record.avatar)
    },
  },
  {
    title: "用户账号",
    dataIndex: "userName",
    width: 100,
  },
  {
    title: "用户姓名",
    dataIndex: "realName",
    width: 100,
  },
  {
    title: "租户名称",
    dataIndex: "tenantName",
    width: 160,
  },
  {
    title: "租户类型",
    width: 80,
    dataIndex: "tenantTypeName",
    customRender: ({ text }) => {
      return render.renderTag(text, "green")
    }
  },
  {
    title: "拥有者",
    width: 60,
    customRender: ({ text }) => {
      let showText = "是"
      let color = "green"
      if (!text) {
        color = "red"
        showText = "否"
      }
      return render.renderTag(showText, color)
    },
    dataIndex: "isOwner",
  },
  {
    title: "状态",
    dataIndex: "status",
    customRender: ({ text }) => {
      let color = "green"
      if (text === "2") {
        color = "red"
      }
      return render.renderTag(render.renderDict(text, "user_status"), color)
    },
    width: 60,
  },
  {
    title: "添加时间",
    dataIndex: "addTime",
    width: 140,
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    label: "账号",
    field: "userName",
    componentProps: {
      placeholder: "用户账号",
    },
    component: "Input",
    colProps: { span: 8 },
  },
  {
    label: "用户状态",
    field: "status",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "user_status",
      placeholder: "请选择状态",
      stringToNumber: true,
    },
    colProps: { span: 8 },
  },
]

export const formDetailSchema: DescItem[] = [
  {
    field: "avatar",
    label: "头像",
    render: (curVal, data) => {
      return render.renderAvatar(curVal)
    },
  },
  {
    field: "userName",
    label: "用户名",
  },
  {
    field: "tenantId",
    label: "租户ID",
  },
  {
    field: "tenantName",
    label: "租户名称",
  },
  {
    field: "tenantTypeName",
    label: "租户类型",
    render: (curVal, data) => {
      return render.renderTag(curVal, "green")
    },
  },
  {
    field: "isOwner",
    label: "拥有者",
    render: (curVal, data) => {
      let showText = "是"
      let color = "green"
      if (!curVal) {
        color = "red"
        showText = "否"
      }
      return render.renderTag(showText, color)
    },
  },
  {
    field: "lastLoginIp",
    label: "最后登录IP",
  },
  {
    field: "lastLoginTime",
    label: "最后登录时间",
  },
  {
    field: "addTime",
    label: "添加时间",
  },
]
